<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

use App\Models\Phones;
use App\Models\Regions;

class Member extends BaseModel
{

    public $table = 'member';
    public $timestamps = true;
    static $unguarded = true;

    const CREATED_AT = 'reg_time';
    const UPDATED_AT = 'update_time';

    protected $hidden = [
        "reg_ip",
        "reg_ip_state",
        "reg_ip_address",
        "original",
        "reg_ip_operator"
    ];

    public static function getMobilerea($phone){
        if (!isset($phone)||empty($phone)) {
            return '';
        }

        $phone = substr($phone,0,7);
        $phones = Phones::where('number', "=", $phone)->first();
        if ($phones) {
            $regions = Regions::where("id", "=", $phones['region_id'])->first();
            $arr = array('北京','上海','天津','重庆');

            if (in_array($regions['province'], $arr)) {
                return $regions['province'];
            }else{
                return $regions['province'] . $regions['city'];
            }

        }else{
            //不存在的记录下下来，维护进去
            file_put_contents('/tmp/phone.log',date('Y-m-d H:i:s').'  '.$phone."\n\n",8);
            return '暂无数据';
        }
    }

}
